package com.anis.project.medcare.calendar;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;

public class SWTDaysHours extends Canvas implements MouseListener {

	private CLabel[] hour = new CLabel[24];
	private String selectedHour;

	public SWTDaysHours(Composite parent) {
		super(parent, SWT.V_SCROLL);
		setBackground(SWTResourceManager
				.getColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
		setLayout(new GridLayout(1, false));

		for (int i = 0; i < 24; i++) {
			hour[i] = new CLabel(parent, SWT.FILL);
			hour[i].setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
			GridData gd_labes = new GridData(SWT.FILL, SWT.CENTER, true, false,
					1, 1);
			gd_labes.heightHint = 54;
			gd_labes.widthHint = 60;
			hour[i].setLayoutData(gd_labes);
			hour[i].setText(String.valueOf(i));
			if (7 <= i && i <= 17)
				hour[i].setBackground(SWTResourceManager
						.getColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));

			hour[i].setSize(parent.getSize().x, 10);
			hour[i].addMouseListener(this);

			Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
			separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
					false, 1, 1));
		}

	}

	@Override
	public void mouseDoubleClick(MouseEvent e) {
		CLabel hour = (CLabel) e.getSource();

		if (!hour.getText().equals("")) {
			this.selectedHour = hour.getText() + "." + "00.00";
			System.out.println("Selected Hour : " + selectedHour);
		}

	}

	@Override
	public void mouseDown(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseUp(MouseEvent e) {
		// TODO Auto-generated method stub

	}
}
